<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\1\17 0017
 * Time: 9:50
 */

class VersionController extends Controller
{
    public $Module = 'api';
    public $Controller = 'version';
    public $Action = 'index';
    public $UserConfig = array();

    public function __construct() {

    }

    /**
     * 获取版本
     */
    public function GetAction()
    {
        $config = \config\ConfigLocal::getLocalConfog();
        ErrorMsg::ApiMsg('ok', 0, array(
            'v_number' => '2.0.12',
            'v_download' => 'http://'.$config->api_domain.'/version/download',
            'v_title' => '更新通知',
            'v_content' => '1.修复图片上传黑屏以及崩溃的问题\n2.修复哈工二手车不显示交易额的问题\n3.优化更新界面布局样式\n4.优化自动升级\n5.修复补录担保人问题正式版\n6.图片限制和pc端同步\n',
        ));
    }

    public function DownloadAction()
    {
        $filename = WEB_PATH.DIRECTORY_SEPARATOR."attsort".DIRECTORY_SEPARATOR."app-carloan-release.apk";
        if(!file_exists($filename)){
            exit("无法找到文件"); //即使创建，仍有可能失败。。。。
        }
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header('Content-disposition: attachment; filename='.basename($filename)); //文件名
        header("Content-Type: application/apk"); //apk格式的
        header("Content-Transfer-Encoding: binary"); //告诉浏览器，这是二进制文件
        header('Content-Length: '. filesize($filename)); //告诉浏览器，文件大小
        @readfile($filename);
    }
}